/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Room;

import Hostel.HostelBean;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author mishra
 */
public class RoomList extends HttpServlet {

    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            Vector<Object> list=Room.Query.viewHostel();
           if(!list.isEmpty())
           {
             Iterator it=list.iterator(); 
              while(it.hasNext())
               {
                   Vector<Object> list1=(Vector) it.next();
                  out.println("<tr id='"+list1.get(0)+"'>");
                  out.println("<td><center>");
                  out.println(list1.get(3));
                  out.println("</center></td>");
                  out.println("<td><center>");
                  out.println(list1.get(4));
                  out.println("</center></td>");
                  out.println("<td><center>");
                  out.println(list1.get(1));
                  out.println("</center></td>");
                  out.println("<td><center>");
                  out.println(list1.get(2));
                  out.println("</center></td>");
                  out.println("<td><center>");
                  if(list1.get(5).toString().equals("0"))
                  {
                      out.println("<span class='label label-important' style='top: -6px;'>"+list1.get(5)+"</span>");
                  }else
                  {
                      out.println("<span class='label label-success' style='top: -6px;'>"+list1.get(5)+"</span>");
                  }
                  out.println("</center></td>");
                  out.println("<td><center>");
                  out.println("<a href='ViewRoom.jsp?hid="+list1.get(0)+"&hname="+list1.get(3)+"'><button class='btn btn-info'>View</button></a>");
                  out.println("<a href='AddMoreRoom.jsp?hid="+list1.get(0)+"&nor="+list1.get(1)+"'><button class='btn btn-warning'>Add Rooms</button></a>");
                  //+"&hname="+hb.getHostelName()+"&htype="+hb.getHostelType()+"&mobile="+hb.getMobile()+"&phone="+hb.getPhone()+"&wardenid="+hb.getWardenId()+"&entrydate="+hb.getEntryDate()+"&address="+hb.getHostelAddress()+
                  out.println("</center></td>");
                  out.println("</tr>");
               }
           }
           else
           {
               out.println("<tr>");
               out.println("<td colspan='3'>");
               out.println("<b>No Record Found</b>");
               out.println("</td>");
               out.println("</tr>");
           }
        } catch(Exception e)
        {
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
